<?php
set_time_limit(0);
dl("php_sdl.dll");

//if(!extension_loaded('sdl_ttf')) {
//	fprintf(STDERR, 'The extension sdl_smpeg must be installed to run this script.' . PHP_EOL);
//	exit(1);
//}

define('APP_TITLE', '09 - True type font rendering');

// Start SDL engine with VIDEO submodule
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
	trigger_error('SDL can not be initialized. Exiting.');
	exit(1);
}

// Create a Window of 640x480, 16 bits of depth
$screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);
if(is_null($screen)) {
	trigger_error('Unable to create a new Window with the desired arguments.');
	exit(1);
}

SDL_WM_SetCaption(APP_TITLE, APP_TITLE);

SDLTTF_Init();

$font = SDLTTF_OpenFont('FreeSans.ttf',50);
$fontHeight = SDLTTF_FontLineSkip($font);

$fontSurf = SDLTTF_RenderUTF8_Solid($font, 'Visca el barça!', 255, 100, 20);
SDL_BlitSurface($fontSurf, null, $screen, array('x' => 40, 'y' => 60));

$fontSurf = SDLTTF_RenderUTF8_Blended($font, 'Visca el barça!', 100, 100, 200);
SDL_BlitSurface($fontSurf, null, $screen, array('x' => 40, 'y' => 60 + $fontHeight));

$fontSurf = SDLTTF_RenderUTF8_Blended($font, 'Visca el barça!', 50, 255, 0);
SDL_BlitSurface($fontSurf, null, $screen, array('x' => 40, 'y' => 60 + $fontHeight * 2));

SDL_Flip($screen);

// Wait till' the user press a mouse button
$event = null;
while(SDL_WaitEvent(&$event)) {
	// If the user presses a button then the program stops
	if($event['type'] == SDL_MOUSEBUTTONDOWN) {
		echo 'Mouse button pressed! Stopping the app.', PHP_EOL;
		break;
	}
}

SDLTTF_Quit();

// Stop SDL engine
SDL_Quit();

?>
